﻿using HDSmartCommunity.DAL;
using HDSmartCommunity.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace HDSmartCommunity.BUS
{
    public class CardBUS
    {
        public List<VoucherInfo> QueryVoucherInfo(VoucherInfo voucher)
        {
            CardInfoDAL da = new CardInfoDAL();
            List<VoucherInfo> list = da.QueryVoucher(voucher);

            foreach (var item in list)
            {
                List<FloorInfo> floorlist = da.GetShowFloor(item.elevatorAuthFloor);
                string showfloor = string.Empty;
                if (floorlist!=null)
                {
                    foreach (var li in floorlist)
                    {
                        showfloor += li.displayfloor + ",";
                    }
                    showfloor=showfloor.TrimEnd(',');
                    item.AuthShowFloor = showfloor;
                }
            }

            return list;
        }

        public bool InsertVoucherInfo(VoucherInfo voucher)
        {
            CardInfoDAL da = new CardInfoDAL();
            bool result = da.InsertVoucherInfo(voucher);
            return result;
        }

        public bool DeleteVoucherInfo(VoucherInfo voucher)
        {
            CardInfoDAL da = new CardInfoDAL();
            bool result = da.DeleteVoucherInfo(voucher);

            return result;
        }

        public int QueryVoucherCount(VoucherInfo voucher)
        {
            CardInfoDAL da = new CardInfoDAL();
            int count = da.QueryVoucherCount(voucher);

            return count;
        }

        public List<FloorInfo> GetFloor()
        {
            CardInfoDAL da = new CardInfoDAL();
            List<FloorInfo> list = da.GetFloor();
            return list;
        }

        public List<Role> GetRole()
        {
            CardInfoDAL da = new CardInfoDAL();
            List<Role> list = da.GetRole();
            return list;
        }

        public List<CredenceType> GetCredenceType()
        {
            CardInfoDAL da = new CardInfoDAL();
            List<CredenceType> list = da.GetCredenceType();
            return list;
        }

    }
}
